home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / Technical.Notes / IIGS / TN.IIGS.079 < prev    next >
Encoding:
Text File  |  1990-05-29  |  6.1 KB  |  117 lines  |  [TEXT/pdos]

  1. Apple II
  2. Technical Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6. Apple IIGS
  7. #79:    Integer Math Data Types
  8.  
  9. Revised by:    Jim Luther                                            May 1990
  10. Written by:    Dan Strnad                                          March 1990
  11.  
  12. This Technical Note describes the format of Fixed and Frac data types used by 
  13. the Integer Math tool set and operations performed on the Integer Math 
  14. numerical data types.
  15. Revised since March 1990:  Fixed original date, bit numbering of diagrams, and 
  16. a multiplication sign in the equation.
  17. _____________________________________________________________________________
  18.  
  19. As stated in Volume 1 of the Apple IIgs Technical Reference, the Integer Math 
  20. tool set provides the following numerical data types:
  21.  
  22.     Integers
  23.     Longints
  24.     Fixed
  25.     Frac
  26.     Extended
  27.  
  28. The precise format of the Fixed and Frac data types is not provided in the 
  29. reference manual, so this Note details these formats.
  30.  
  31. The format for the Fixed data type is stated in the manual as being a 32-bit 
  32. signed value with 16 bits of fraction.  This means that the low-order 16 bits 
  33. of the Fixed format data value are considered as a fraction of 2^16, which is 
  34. the binary number represented by a one followed by 16 zeroes ($10000).  In 
  35. other words, a Fixed value is the same as a long integer value whose binary 
  36. point has been moved to the left 16 places.  In this representation, if the 
  37. low-order part of the Fixed format data value were $8000, the fractional value 
  38. would be equal to 1/2.  A low-order part of $C000 would represent a fractional 
  39. part equal to 3/4.  Therefore the highest value that a Fixed can contain is 
  40. 32,767 and 65,535/65,536; the least value is equal to -32768.
  41.  
  42.      31         30         29                     18         17         16
  43.  __________ __________ __________ ___________ __________ __________ __________
  44. |          |          |          |           |          |          |          |
  45. |  -32768  |  16384   |   8192   |    ...    |    4     |    2     |    1     |
  46. |          |          |          |           |          |          |          |
  47. |__________|__________|__________|___________|__________|__________|__________|
  48.                                 high-order word
  49.  
  50.      15         14         13                     2          1          0
  51.  __________ __________ __________ ___________ __________ __________ __________
  52. |    1     |    1     |    1     |           |    1     |    1     |    1     |
  53. |    -     |    -     |    -     |    ...    |  -----   |  -----   |  -----   |
  54. |    2     |    4     |    8     |           |  16384   |  32786   |  65536   |
  55. |__________|__________|__________|___________|__________|__________|__________|
  56.                                 low-order word
  57.  
  58.                            Figure 1-Fixed Data Type
  59.  
  60. The format for the Frac data type is stated in the manual as being a 32-bit 
  61. signed value with 30 bits of fraction.  This means that the low-order 30 bits 
  62. of the Frac format data value are considered as a fraction of 2^30, which is 
  63. the binary number represented by a one followed by 30 zeroes ($40000000).  In 
  64. other words, a Frac value is the same as a long integer value whose binary 
  65. point has been moved to the left 30 places.  The high-order 2 bits of the Frac 
  66. format data value are treated as follows.  The high bit has a value of -2 and 
  67. the low bit has a value of 1.  Therefore the highest value that a Frac can 
  68. contain  is 1 and ((2^30)-1)/2^30; the least value is equal to -2. 
  69.  
  70.      31         30         29                     18         17         16
  71.  __________ __________ __________ ___________ __________ __________ __________
  72. |          |          |    1     |           |    1     |    1     |    1     |
  73. |    -2    |    1     |    -     |    ...    |   ----   |   ----   |  -----   |
  74. |          |          |    2     |           |   4096   |   8192   |  16384   |
  75. |__________|__________|__________|___________|__________|__________|__________|
  76.                                 high-order word
  77.  
  78.      15         14         13                     2          1          0
  79.  __________ __________ __________ ___________ __________ __________ __________
  80. |    1     |    1     |    1     |           |    1     |    1     |    1     |
  81. |  -----   |  -----   |  ------  |    ...    |--------- |--------- |----------|
  82. |  32768   |  65536   |  131072  |           |268435456 |536870912 |1073741824|
  83. |__________|__________|__________|___________|__________|__________|__________|
  84.                                 low-order word
  85.  
  86.                            Figure 2-Frac Data Type
  87.  
  88. Note that for Longints, Fixed, and Frac values, the hex representations of the 
  89. largest and smallest data values are $7FFFFFFF and $80000000, respectively.
  90.  
  91. A property of the Fixed and Frac data types is that two Fixed or two Frac 
  92. values may be added or subtracted just as if they were 32-bit integers.  To 
  93. demonstrate this, imagine scaling the numbers by a given factor to make them 
  94. integers.  After adding the numbers, the sum could be scaled back down by the 
  95. same factor.  This follows from the distributive property of multiplication 
  96. over addition, which allows one to make the inference shown in the equations 
  97. which follow.  In these equations, V1 and V2 are both either Fixed or Frac 
  98. values. The value for C being discussed, which illustrates the ability to 
  99. scale Fixed and Frac values, is 2^16 for Fixed values of V1 and V2, or 2^30 
  100. for Frac values of V1 and V2.
  101.  
  102.         (C * V1) + (C * V2)     C * (V1 + V2)
  103.         ___________________  =  _____________  = V1 + V2
  104.                  C                    C
  105.  
  106. Similarly, two Fixed or two Frac values may be compared, as Longints are 
  107. compared, with one another.  In general, the comparison, addition, and 
  108. subtraction operations used for  long integers may also be performed on any 
  109. two Fixed or any two Frac values.
  110.  
  111.  
  112. Further Reference
  113. _____________________________________________________________________________
  114.   o  Apple IIGS Technical Reference Manual
  115.   o  Apple Numerics Manual, Second Edition
  116.  
  117.